/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presenter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import model.MetodoIMC;
import view.CalculoIMCAdultoView;

/**
 *
 * @author jakson
 */
public class CalculoIMCAdultoPresenter {

    private CalculoIMCAdultoView view;
    private MetodoIMC imc = new MetodoIMC();
    double peso = 0;
    double altura = 0;
    char sexo = 0;

    public CalculoIMCAdultoPresenter() {
        view = new CalculoIMCAdultoView(null, true);

        view.getBtnCancelar().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                view.dispose();
            }
        });

        view.getBtnCalcular().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                calculaImc();
            }
        });

        view.setLocationRelativeTo(view);
        view.setVisible(true);

    }

    public void calculaImc() {
        peso = Double.parseDouble(view.getCampoPeso().getText());
        altura = Double.parseDouble(view.getCampoAltura().getText());
        sexo = view.getComboxSexo().getSelectedItem().toString().charAt(0);
        imc.fazerCalculo(peso, altura);
        imc.classificar(sexo);
        double imcPessoa = imc.getImc();
        DecimalFormat fmt = new DecimalFormat("0.00");     
        String string = fmt.format(imcPessoa);
        view.getLabelImc().setText(string);
        view.getLabelResultado().setText(imc.getCondicao());

    }
}
